SetLocalTime (kernel32)
Last changed: -108.7.199.68

.
Summary
Sets the current local time and date.

C# Signature:

[DllImport("kernel32.dll")]
static extern bool SetLocalTime([In] ref SYSTEMTIME lpLocalTime);

VB Signature:

<DllImport("kernel32.dll")> _
Shared Function SetLocalTime(ByRef time As SYSTEMTIME) As Boolean
End Function

User-Defined Types:

None.

Notes:

Please add some!

Tips & Tricks:

Please add some!

Sample Code in VB:

Imports System.Runtime.InteropServices

Public Class Class1
   <StructLayout(LayoutKind.Sequential)> _
   Private Structure SYSTEMTIME
     <MarshalAs(UnmanagedType.U2)> Public Year As Short
     <MarshalAs(UnmanagedType.U2)> Public Month As Short
     <MarshalAs(UnmanagedType.U2)> Public DayOfWeek As Short
     <MarshalAs(UnmanagedType.U2)> Public Day As Short
     <MarshalAs(UnmanagedType.U2)> Public Hour As Short
     <MarshalAs(UnmanagedType.U2)> Public Minute As Short
     <MarshalAs(UnmanagedType.U2)> Public Second As Short
     <MarshalAs(UnmanagedType.U2)> Public Milliseconds As Short
   End Structure

   <DllImport("kernel32.dll")> _
   Private Shared Sub GetLocalTime(ByRef time As SYSTEMTIME)
   End Sub

   <DllImport("kernel32.dll")> _
   Private Shared Function SetLocalTime(ByRef time As SYSTEMTIME) As Boolean
   End Function

   Public Sub SetsLocalTimeHourToEight()
     Dim currentTime As SYSTEMTIME
     GetLocalTime(currentTime)

     currentTime.Hour = 8

     SetLocalTime(currentTime)
   End Sub
End Class

Alternative Managed API:

Do you know one? Please contribute it!

Documentation